<template>
  <div>
      <el-form>
        <div style="margin: 16px;font-size:16px;">
          <div class="row">
            1.检查并确认ADRU电门在OFF位
          </div>

          <el-radio-group v-model="form.c1" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            2.检查并确认应急灯选择电门在OFF位。
          </div>

          <el-radio-group v-model="form.c2" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            3.检查并确认机组氧气系统ON灯不亮(空客系列飞机)。
          </div>

          <el-radio-group v-model="form.c3" direction="horizontal">
            <el-radio label="1">不适用</el-radio>
            <el-radio label="2" style="margin-left:10px">是</el-radio>
            <el-radio label="3" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            4.检查并确认空调组件关闭。
          </div>

          <el-radio-group v-model="form.c4" direction="horizontal" >
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            5.检查并确认APU引气关闭。
          </div>

          <el-radio-group v-model="form.c5" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            6.检查并确认APU主电门关闭。
          </div>

          <el-radio-group v-model="form.c6" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            7.检查并确认:A330APU电瓶关闭。
          </div>

          <el-radio-group v-model="form.c7" direction="horizontal">
            <el-radio label="1">不适用</el-radio>
            <el-radio label="2" style="margin-left:10px">是</el-radio>
            <el-radio label="3" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            8.检查并确认主电瓶关闭。
          </div>

          <el-radio-group v-model="form.c8" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            9.检查并确认飞机各舱门、窗户关闭。
          </div>

          <el-radio-group v-model="form.c9" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>

          <div class="row">
            10.清点工具。
          </div>
          <el-radio-group v-model="form.c10" direction="horizontal">
            <el-radio label="1">是</el-radio>
            <el-radio label="2" style="margin-left:10px">否</el-radio>
          </el-radio-group>
        </div>
        <div style="padding: 20px;">
          <div class="row">
            工作者：
            <el-input v-model="form.n1" name="n1" disabled placeholder="请输入工作者" />
          </div>
          <div class="row">
            审核者：
            <el-input v-model="form.n2" name="n2" disabled placeholder="-" />
          </div>
        </div>
       
      </el-form>
      <div style="padding: 20px;">
        <el-button block type="primary" @click="onSubmit">
          提交
        </el-button>
      </div>
  </div>
</template>
<script>
import { edit, toExamine, queryById } from "@/api/airport/outfield";
import { oauthUser, queryString, getLoginInfo } from "@/api/wcLogin";
export default {
  computed: {
    c1Show () {
      return this.form.c1.indexOf('5') !== -1
    },
    c2Show () {
      return this.form.c2.indexOf('5') !== -1
    }
  },
  data () {
    return {
      // 表单参数
      form: {
        c1: '',
        c2: '',
        c3: '',
        c4: '',
        c5: '',
        c6: '',
        c7: '',
        c8: '',
        c9: '',
        c10: '',

        n1: '',
        n2: '',
      },
      routeParam: {},
      wxUser:undefined,
    };
  },
  created () {
    this.routeParam = this.$route.query;
    queryById({ id: this.$route.query.id }).then(res => {
      const workerInspectTerm = res.data?.inspectTimestamp ?  res.data.inspectTimestamp : 0;
      const reviewerInspectTerm =  res.data?.reviewerTimestamp ?  res.data.reviewerTimestamp : 0;
      let item = {};
      if (workerInspectTerm > reviewerInspectTerm) {
        item = res.data.workerInspectTerm;
      } else {
        item = res.data.reviewerInspectTerm;
      }
      if (item) {
        item.forEach(item => {
          for (let i in item.content) {
            this.form[i] = item.content[i];
          }
        });
      }
      if (this.routeParam.source === 'edit') {
        this.form.n1 = res.data.worker;
      }
      // this.form.n1 = res.data.worker;
      // this.form.n2 = res.data.reviewer;
    })
    const user = JSON.parse(sessionStorage.getItem('userInfo'))
    this.wxUser = user;
    if (this.routeParam.source === 'edit') {
      this.form.n2 = user.nickName;
    } else {
      this.form.n1 = user.nickName;
    }
  },
  methods: {
    onSubmit (values) {

      const inspect = [];
      for (let i = 1; i <= 10; i++) {
        inspect.push({
          index: i,
          content: { [`c${i}`]: this.form[`c${i}`] },
        })
      }
      const data = {
        inspectDTOS: inspect,
        id: this.$route.query.id,
        name: this.wxUser.nickName,
      }
      console.log(data, 'data');

      if (this.$route.query.source === 'add') {
        edit(data).then((res) => {
          this.$message.success("成功");
          this.$router.push({ name: 'Menu', replace: true })
        });
      } else if (this.$route.query.source === 'edit') {
        toExamine(data).then((res) => {
          this.$message.success("成功");
          this.$router.push({ name: 'Menu', replace: true })
        });
      }

    },
  },
};
</script>


<style lang='scss' scoped>
.row {
  position: relative;
  display: flex;
  box-sizing: border-box;
  width: 100%;
  flex-direction: column;
  padding: var(--van-cell-vertical-padding) var(--van-cell-horizontal-padding);
  overflow: hidden;
  color: var(--van-cell-font-size);
  font-size: var(--van-cell-font-size);

  &:after {
    position: absolute;
    box-sizing: border-box;
    content: "";
    right: var(--van-padding-md);
    bottom: 0;
    left: var(--van-padding-md);
    pointer-events: none;
    border-bottom: 1px solid var(--van-cell-border-color);
    transform: scaleY(0.5);
  }
}
.head {
  position: fixed;
  top: 0;
  z-index: 1;
  width: 100%;
  background: #fff;
}
.bottom {
  position: fixed;
  bottom: 0;
  z-index: 1;
  width: 100%;
  background: #fff;
}
.mt46 {
  padding-bottom: 56px;
}
</style>